<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工工资管理子页面</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){
	//默认结算工资对话框是关闭的
	$('#jiesuangongzi').dialog('close');
	//配置数据表格，显示员工数据
	$('#stuMsg').datagrid({
		url : '${pageContext.request.contextPath}/xianshiEmployees',
		columns : [ [ {
			field : 'checked',
			checkbox : true,
			width : 100
		}, {
			field : 'elId',
			title : '职工号',
			width : 100,
			hidden : false
		}, {
			field : 'elName',
			title : '职工姓名',
			width : 100
		}, {
			field : 'dName',
			title : '所属部门',
			width : 100,
		}, {
			field : 'salary',
			title : '职工工资',
			width : 100,
		}, {
			field : 'state',
			title : '是否离职',
			width : 100,
		}, ] ],
		pagination : true,   //显示分页
		striped : true,
		rownumbers : true,
		singleSelect:true //禁止多选
	});
	
	//配置工资结算表单
	$("#jiesuanSalary").form({
		url : '${pageContext.request.contextPath}/jiesuanEmployeeSalary',
		success : function(data) {
			if (data == "1") {
				$.messager.alert('我的消息', '结算成功', 'info', function() {
					$('#stuMsg').datagrid('reload');
				});
				$('#jiesuangongzi').dialog('close');
				$("#jiesuanSalary").form('clear');
			} else {
               alert("结算失败,该员工当月的工资已结算过");
			}
		}
	})
	
	//配置搜索框
	$('#searchEmpl').searchbox({
		searcher : function(value, name) {
			var elName = value;
			$('#stuMsg').datagrid('reload', {
				searchName : elName
			});
		}
	});
	//设置结算日期为当前时间	
	formatterDate = function(date) {
			var day = date.getDate() > 9 ? date.getDate() : "0"
					+ date.getDate();
			var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1)
					: "0" + (date.getMonth() + 1);
			return date.getFullYear() + '-' + month + '-' + day;
		};
	//点击工资结算，显示工资结算对话框
	$("#gongzijiesuanButton").click(function(){
		var stus = $("#stuMsg").datagrid('getSelections');
		if (stus==0) {
			$.messager.alert('我的消息', '请选择需要结算工资的员工', 'info', function() {
				$('#stuMsg').datagrid('reload');
			});
		}
		else{
			var em11 = $("#stuMsg").datagrid('getSelected');
			if (em11.state=="是") {
				$.messager.alert('我的消息', '该员工已离职，你还发工资，想亏死劳资啊', 'info', function() {
					$('#stuMsg').datagrid('reload');
				});
			}
			else {
				$('#jiesuangongzi').dialog('open');//打开工资结算对话框
				var empl = stus[0];
				$('#jiesuanSalary').form('load', empl); //把勾选的员工数据读入对话框
			}
			
		}
		//把当前日期读到date（结算日期）里
		$('#date').datebox('setValue',
				formatterDate(new Date()));
	});
	
	
 })
   //配置结算工资表单提交事件
	function jiesuanMoney() {
		$("#jiesuanSalary").form('submit');
	}
</script>
<body>
	<!-- 模糊查询 -->
	<input id="searchEmpl" class="easyui-searchbox" data-options="prompt:'输入姓名查询工资',width:150">
	<!-- 工资结算按钮 -->
	<button id="gongzijiesuanButton" type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off" style="margin-left: 500px;">
  工资结算
  </button>
	
	<!-- 显示界面 -->
	<table id="stuMsg"></table>
	
	<!-- 结算工资对话框 -->
	<div id="jiesuangongzi" class="easyui-dialog" title="员工工资信息"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="jiesuanSalary" method="post">
			<div style="margin-bottom: 20px;">
				<span>员工编号</span> <input class="easyui-textbox" name="elId" id="s_elId" readonly="readonly"
					style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>员工姓名</span> <input class="easyui-textbox" name="elName" id="elName" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>员工工资</span> <input class="easyui-textbox" name="salary" id="salary" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>结算日期</span> <input class="easyui-datebox" name="date" id="date" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>工资日期</span> <input class="easyui-datebox" name="salaryDate" id="salaryDate"
					style="width: 100%;" data-options="required: true,missingMessage:'工资日期不能为空'">
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="jiesuanMoney()" style="width: 80px">确定结算</a>
		</div>
	</div>


</body>
</html>